package cn.com.easy.permission.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.easy.permission.dao.OptionLogDao;
import cn.com.easy.permission.model.OptionLogModel;
import cn.com.easy.permission.mybatis.OptionLogMybatisDao;
import cn.com.easy.permission.service.system.urlreserve.anotion.UrlReserveAnotion;
import cn.com.easy.permission.web.dto.MessageDTO;
import cn.com.easy.permission.web.dto.PageRequestParamDTO;
import cn.com.easy.permission.web.dto.system.OptionLogParam;
import cn.com.easy.utils.PageUtils;
import cn.com.easy.utils.ResponseOutputUtils;

import com.github.miemiedev.mybatis.paginator.domain.PageList;

/**
 * 操作日志
 * 
 * @author nibili 2017年12月21日
 * 
 */
@Controller
@RequestMapping("/manage/system/option_log")
public class SystemOptionLogController extends BaseController {

	private Logger logger = LoggerFactory.getLogger(SystemOptionLogController.class);

	/** 操作日志dao */
	@Autowired
	private OptionLogDao optionLogDao;
	/** 操作日志mybatis dao */
	@Autowired
	private OptionLogMybatisDao optionLogMybatisDao;

	/**
	 * 操作日志首页
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @author nibili 2017年12月22日
	 */
	@UrlReserveAnotion("操作日志首页")
	@RequestMapping("")
	public String index(HttpServletRequest request, HttpServletResponse response) {
		return "/system/system_option_log/system_option_log";
	}

	/**
	 * 获取操作日志
	 * 
	 * @param request
	 * @param response
	 * @param pageRequestParamDTO
	 * @param optionLogParam
	 * @author nibili 2017年12月22日
	 */
	@UrlReserveAnotion("获取操作日志")
	@RequestMapping("/get/all")
	public void getAllMembers(HttpServletRequest request, HttpServletResponse response, PageRequestParamDTO pageRequestParamDTO, OptionLogParam optionLogParam) {
		try {

			if (StringUtils.isBlank(pageRequestParamDTO.getSortName()) == true) {
				pageRequestParamDTO.setSortName("createTime");
				pageRequestParamDTO.setSortOrder("desc");
			}
			PageList<OptionLogModel> pageList = optionLogMybatisDao.find(optionLogParam, pageRequestParamDTO.buildMyBatisPageRequest());
			cn.com.easy.utils.Page<OptionLogModel> page = PageUtils.getPage(pageList);
			// page.setTotalItems(1000);
			ResponseOutputUtils.renderJson(response, MessageDTO.newInstance("", true, page));
		} catch (Exception ex) {
			logger.error("获取操作日志异常.", ex);
			ResponseOutputUtils.renderJson(response, MessageDTO.newInstance("", false, "获取操作日志异常.ex:" + ex.getLocalizedMessage()));
		}
	}
}
